<?php
/**
 * 线路类
 * @author jroam
 *
 */
class tourAction extends globalAction
{
    /**
     * 线路列表
     */
    function search() {
        $field = array(
            '*',
            "(select count(*) from ".C("DB_PREFIX")."pinglun where pinglun2=tour0)" => "pinglunnum"
        );
        $order = array(
            'tour42'=>'desc',//一级排序
            'tour43'=>'desc',//二级排序
            'tour48'=>'desc',//修改时间
            //'tour53'=>"desc",//DIT指数
            //"tour55"=>"desc",//人气值
            //"tour51"=>"desc",//想去的人数
            //"tour39"=>"desc",//点击查看数
            //"tour8" =>"desc",//价格
            //"tour7" =>"desc",//持续天数
        );
        $limit = 10;
        $condition["tour44"] = array("eq",1212);//已审核
        $condition["tour41"] = array("eq","cn");//中文线路
        //出发地
        if($from = intval($_GET["from"])) {
            $condition["tour10"] = array("like", "%,$from,%");
            $dest_condition['tour10'] = array("like", "%,$from,%");
        } else {
            $condition["tour10"] = array("like", "%," . __FromDestID__ . ",%");//出发地
            $dest_condition['tour10'] = array('like', "%," . __FromDestID__ . ",%");
        }
        //产品类型
        if($type = intval($_GET["type"])) {
            $condition["tour40"] = array("like", "%,$type,%");
            $dest_condition["tour40"] = array("like", "%,$type,%");
        }
        //特色
        if($feature = intval($_GET["feature"]))
            $condition["tour50"] = array("like", "%,$feature,%");
        //景点
        if($scenic = intval($_GET["scenic"]))
            $condition["tour49"] = array("like", "%,$scenic,%");
        //行程天数
        if($days = intval($_GET["days"]))
            $condition["tour7"] = array("eq", $days);
        //关键字
        if($keywords = intval($_GET["keywords"]))
            $condition["tour1"] = array("like", "%$keywords%");

        //线路类型
        $tourtypes = M("classsys")->field(array(
                        "classsys0"=>"id",
                        "classsys1"=>"name_cn",
                        "classsys7"=>"name_cn"
                    ))
                    ->where("classsys3=569")
                    ->order("classsys4 desc")
                    ->select();
        $this->assign("tourtypes", $tourtypes);

        $destsid = M("tour")->field("tour9")
                    ->where($dest_condition)
                    ->select();

        //线路列表
        $tours = M("tour")
                ->field($field)
                ->where($condition)
                ->order($order)
                ->limit($limit)
                ->select();
        $this->assign("tours", $tours);

        $this->display();
    }



	/**
	 * 获取并返回线路类的多条记录
	 * @param $wheresql  查询的sql语句
	 * @return 返回新闻类的多条记录  失败返回null
	 */
	public function getRsList($wheresql)
	{
		$rsc=M("tour");
		$rs= $rsc->where($wheresql)->select();
		return ($rs)?$rs:"";
	}



	 /**
	 * 获取并返回线路类的一条记录
	 * @param $wheresql  查询的sql语句
	 * @return 返回线路类的单条记录  失败返回null
	 */
	public function getrsone($wheresql)
	{

		$rsc=M("tour");
		$rs= $rsc->where($wheresql)->find();
		$this->assign("rs",$rs);
		return ($rs)?$rs:"";

	}

	function showlist()
	{
		$mr=M("tour");
		$rs=fanye($mr,"1=1",2,"1","");
		$this->assign("rs",$rs["rs"]);
		$this->assign("show",$rs["show"]);
		$this->display();

	}

	/**
	 * 显示线路详细页面
	 */
	function view()
	{

		global $SYS_config;
		$id=$_REQUEST["id"];
		if(!is_numeric($id)) die("参数不对");

		//获取类别导航
		//获取左边的栏目导航的类别
		//$classsys=A("classsys");
		//$cladhtm=$classsys->getteshe();

		$mr=M("tour");
		$sql="select * from ".DQ."tour as a  ,(select * from ".DQ."price  order by price8 asc) as b where a.tour0=$id and b.price7=a.tour0  limit 0,1";
		$temp=M()->query($sql);
		$rs=$temp[0];
		if(!$rs) die("没有这条线路或这条线路没有添加价格");



		//定义印象背景颜色,前台随机取一个,每一行的第二个样式加margin5
		$yingxbgc=array("bq_green","bq_lightgreen","bq_blue","bq_yellow");

		//获取这条线路的印象记录
		$yxmr=A("pinglun");
		$uid=$_COOKIE["uchome_uid"];
		$uchome_auth=$_COOKIE["uchome_auth"];
		if($uchome_auth){
			//$yxrs=$yxmr->getrslist("pinglun4=$uid and pinglun3=580 and pinglun2=$id order by pinglun0 desc limit ".$SYS_config["addYingx"]);
		}


		//获取这条线路的好评率
		//$haoping=$yxmr->gettourhaopinglv($id);
		//获取这条线路的评论数
		$sql="select count(*) as pnum from ".DQ."pinglun where pinglun2=$id and pinglun3=579";
		$pnum=M()->query($sql);

		//获取这条线路的想去数
		$sql="select count(*) as num from ".DQ."guanzhu where guanzhu2=$id";
		$xiangunum=M()->query($sql);

		//特别关键字样式
		$tebiacss=array("zs bold font16 wy margin5","yellow font12 wy margin5","gray font20 wy");

		//折分一个特别关键字字符串为数组
		$tebs=preg_split("/[,\s，\.。]/", $rs["tour54"]);

		//拆分行程内容为多天.
		$xingcecontent=$rs["tour23"];
		$xingcecontentar=explode(DanxuangduofenC, $rs["tour23"]);


		//获取相关游记内容
		$youjikeywordarr=preg_split("/[,\s，\.。]/", $rs["tour56"]);
		$subsql="";
		foreach ($youjikeywordarr as $v)
		{
			$subsql.=" and a.subject like '%".$v."%'";
		}
		//获取游记攻略
		$myuser=A("user");
		$sql="select a.blogid,a.uid,a.dateline,a.subject,a.pic,a.hot,a.viewnum,a.replynum from ".UHDQ."blog as a left join ".UHDQ."space as b on a.uid=b.uid
		 where a.pic<>'' $subsql
		order by a.dateline desc limit 0,20";
		//$youji=$myuser->getRsListBySql($sql);

		//获取相关线路tour54
		$subsql="";
		foreach ($tebs as $v)
		{
			$subsql.=" and tour1 like '%".$v."%'";
		}

		$wsql="tour44=1212 and tour41='cn' and tour0<>$id ".$subsql." order by tour42 desc,tour43 desc,tour0 desc limit 0,20";
		$pnumsql="(select count(*) from ".DQ."pinglun where pinglun2=a.tour0) as pingluncount";
		$sql="select *,$pnumsql from ".DQ."tour as a where ".$wsql;
		$xgrs=M()->query($sql);


		//获取此行程的相关点评
		$sql="select * from ".DQ."pinglun where pinglun3=579 and pinglun2=$id order by pinglun0 desc limit 0,10";

		$pinglunrs=M()->query($sql);



		//获取此行程所有的价格列表
		//获取这条线路的想去数
		$sql="select * from ".DQ."price as a left join ".DQ."classsys as b on a.price5=b.classsys0 where a.price7=$id";
		$toursprice=M()->query($sql);

		$this->assign("rs",$rs);
		$this->assign("tophtml",$tophtml);
		$this->assign("cladhtm",$cladhtm);
		$this->assign("yingxbgc",$yingxbgc);
		$this->assign("yxrs",$yxrs);
		$this->assign("haopinglv",$haoping);
		$this->assign("xiangunum",$xiangunum[0]["num"]);
		$this->assign("tebiacss",$tebiacss);
		$this->assign("pnum",$pnum[0]["pnum"]);
		$this->assign("tebs",$tebs);
		$this->assign("xingcecontentar",$xingcecontentar);
		$this->assign("youji",$youji);
		$this->assign("xgrs",$xgrs);
		$this->assign("toursprice",$toursprice);
		$this->assign("pinglunrs",$pinglunrs);
		$this->display();

	}


	function addrenqi()
	{
		$tid=$_REQUEST["tid"];
		if(!is_numeric($tid)) die("线路id不正确");
		$mr=M("tour");
		$mr->where("tour0=$tid")->setInc('tour55'); //tour55加1
		$rs=$mr->where("tour0=$tid")->find();
		if($rs){
			echo $rs["tour55"];
		}
		else
		{
			echo "没有此记录";
		}
	}

	/**
	 * 线路搜索页面
	 */
	function searchtour()
	{
		//获取头部
		$public=A("public");
		$tophtml=$public->top();
		$keyword=$_REQUEST["keyword"];//搜索关键字
		$sqlsub="";
		//初始化查询条件  $keyword
		if($keyword) $sqlsub.=" and a.tour1 like '%".$keyword."%'";


		//=======================================分析行程天数
		$tianshu=$_REQUEST["tianshu"];//行程天数
		if(is_numeric($tianshu)) $sqlsub.=" and a.tour7=".$tianshu;
		//分析大于某一天的行程数
		$temp=getkuohaostr($tianshu,"/^[d]([\d]+)$/");
		$sqlsub.=(is_numeric($temp))?" and a.tour7>".$temp:"";
		//分析小于某一天的行程数
		$temp=getkuohaostr($tianshu,"/^[x]([\d]+)$/");
		$sqlsub.=(is_numeric($temp))?" and a.tour7<".$temp:"";

		//获取线路列表
		$sql="select * ,(select count(*) from ".DQ."pinglun where pinglun2=a.tour0) as pingluncount
			from ".DQ."tour as  a , (select min(price8) as bprice8,price7,price6 from ".DQ."price group by price7) b where a.tour44=1212 and a.tour0=b.price7 ".$sqlsub." order by a.tour0 desc";

		$mr=M("tour");
		$rs=fanye($mr,$sql,1,2);

		//获取类别导航
		//获取左边的栏目导航的类别
		$classsys=A("classsys");
		$cladhtm=$classsys->getteshe();

		$this->assign("rs",$rs["rs"]);
		$this->assign("fanyehtml",$rs["show"]);
		$this->assign("tophtml",$tophtml);
		$this->assign("cladhtm",$cladhtm);
		$this->assign("keyword",$keyword);
		$this->display();
	}

	/**
	 * 线路列表
	 */
	function tourlist()
	{
		//获取头部
		$public=A("public");
		$tophtml=$public->top();

		//=======================================分析行程天数
		$tianshu=$_REQUEST["tianshu"];//行程天数
		if(is_numeric($tianshu)) $subsql=" and a.tour7=".$tianshu;
		//分析大于某一天的行程数
		$temp=getkuohaostr($tianshu,"/^[d]([\d]+)$/");
		$subsql.=(is_numeric($temp))?" and a.tour7>".$temp:"";
		//分析小于某一天的行程数
		$temp=getkuohaostr($tianshu,"/^[x]([\d]+)$/");
		$subsql.=(is_numeric($temp))?" and a.tour7<".$temp:"";

        //设置页面的属性
		$temp=getsubstr($tianshu,"/[\d]+/");
		$pagec=array();
		if($temp){
			$pagec["pagetitle"]="周边".$temp."日游,".$temp."天行程,".$temp."日游";
			$pagec["contenttitle"]="周边所有".$temp."日游";
		}

		//=======================================================================获取特色类别
		$tslb=$_REQUEST["tslb"];//特色类别id
		$lbid=$_REQUEST["lbid"];//关联景点id
		if(is_numeric($tslb) and is_numeric($lbid)){
			$sql="select * from ".DQ."classsys where classsys0=$tslb";
			$tslbrs=$public->query($sql);
			$sql="select * from ".DQ."classsys where classsys0=$lbid ";
			$lbidrs=$public->query($sql);

			$pagec["pagetitle"]=$tslbrs[0]["classsys1"]."旅游线路,".$lbidrs[0]["classsys1"]."旅游线路";
			$pagec["contenttitle"]=$tslbrs[0]["classsys1"].$lbidrs[0]["classsys1"]."旅游线路";

			$subsql.=" and a.tour50 like '%".$tslb."%' and a.tour49=".$lbid;

		}


		//=============================================================================获取目的地属性
		$mdd=$_REQUEST["mdd"];
		if(is_numeric($mdd)){
			$mddrs=$public->query("select * from ".DQ."classsys where classsys0=".$mdd);
			$subsql.=" and a.tour9=".$mdd;
			$pagec["pagetitle"]=$mddrs[0]["classsys1"]."旅游线路,".$mddrs[0]["classsys1"]."旅游报价,".$mddrs[0]["classsys1"]."旅游线路怎么样";
			$pagec["contenttitle"]=$mddrs[0]["classsys1"]."旅游线路";
		}



		//获取线路列表
		$sql="select * ,(select count(*) from ".DQ."pinglun where pinglun2=a.tour0) as pingluncount
			from ".DQ."tour as  a , (select min(price8) as bprice8,price7,price6 from ".DQ."price group by price7) b where a.tour44=1212 and a.tour0=b.price7 ".$subsql." order by a.tour0 desc";



		$mr=M("tour");
		$rs=fanye($mr,$sql,10,2);




		//获取类别导航
		//获取左边的栏目导航的类别
		$classsys=A("classsys");
		$cladhtm=$classsys->getteshe();

		$this->assign("rs",$rs["rs"]);
		$this->assign("fanyehtml",$rs["show"]);
		$this->assign("tophtml",$tophtml);
		$this->assign("cladhtm",$cladhtm);
		$this->assign("pagec",$pagec);

		$this->display();
	}

}

?>